#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
	int n, x;
	while (cin >> n >> x)
	{
		int ans;
		int arr[25];
		for (int i = 0;i <= n;i++)
		{
			cin >> arr[i];
		}
		ans = arr[n];
		for (int i = n-1; i >= 0; i--)
		{
			ans = ans * x + arr[i];
		}
		cout << ans << endl;
	}
	return 0;
}